//
//  LHCFirstViewController.m
//  UIimageViewDemo
//
//  Created by lihongcheng on 16/4/13.
//  Copyright © 2016年 lihongcheng. All rights reserved.
//

#import "LHCFirstViewController.h"
#import "LHCSecondViewController.h"
#import "LHCMyProtocol.h"
#import "LHCImageView.h"

#define W    [[UIScreen mainScreen] bounds].size.width
#define H    [[UIScreen mainScreen] bounds].size.height


@interface LHCFirstViewController ()<LHCMyProtocol>

@property (nonatomic,assign) NSInteger flag;


@end

@implementation LHCFirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"图片展示";
    [self createMainView];
}

-(void)createMainView
{
    NSArray *imageArray = @[@"2_1.jpg",@"2_2.jpg",@"2_3.jpg",@"2_4.jpg",@"2_5.jpg",@"2_6.jpg",@"2_7.jpg",@"2_8.jpg",@"2_9.jpg",@"2_10.jpg",@"2_11.jpg",@"2_12.jpg",@"2_13.jpg",@"2_14.jpg",@"2_15.jpg"];
    for (int i = 0; i < imageArray.count; i++) {
        
        LHCImageView *showImage = [[LHCImageView alloc] initWithFrame:CGRectMake(5+(i%4)*((W-25)/4.0)+5*(i%4), 64+(((W-25)/4.0)*1.3)*(i/4)+(5*(i/4)), (W-25)/4.0, ((W-25)/4.0)*1.3)];
        
        showImage.image = [UIImage imageNamed:imageArray[i]];
        showImage.tag = 100+i;
        //让图片可点击
        showImage.userInteractionEnabled  = YES;
        [self.view addSubview:showImage];
        
        //添加手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageClick:)];
        [showImage addGestureRecognizer:tap];
        
    }
}

-(void)setImageTitle:(NSString *)title
{
    LHCImageView *showImage = (LHCImageView *)[self.view viewWithTag:self.flag];
    showImage.titleLabel.text = title;
    
}


-(void)tapImageClick:(UITapGestureRecognizer *)tap
{
    LHCImageView *showImage = (LHCImageView *)[self.view viewWithTag:tap.view.tag];
    self.flag = tap.view.tag;
    LHCSecondViewController *svc = [[LHCSecondViewController alloc] init];
    svc.imageName = showImage.image;
    svc.delegate = self;
    [self.navigationController pushViewController:svc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
